package com.hzqy.service.epg;


import com.hzqy.persistence.dao.epg.AcWchatTvUserOrgDao;
import com.hzqy.web.vo.SysAreaStreetVo;
import com.hzqy.web.vo.epg.AcWchatTvGameVo;
import com.hzqy.web.vo.epg.AcWchatTvUserWeixinVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import sun.rmi.runtime.Log;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AcWchatTvOrgService {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private AcWchatTvUserOrgDao acDao;
	public  Map<String,Object> selectAc(Map<String,Object> map,int page, int rows){
		String periods = Periods();
		map.put("f_wtgo_periods",periods);
        Integer rowCount = acDao.selectAcCount(map);
        map.put("total", rowCount);
        if(rowCount>0 && page>0 && rows>0){
            map.put("firstResult", (page-1)*rows);
            map.put("maxResults", rows);
            List<AcWchatTvUserWeixinVo> list=acDao.selectAcByRequest(map);
            map.put("rows", list);
        }else{
            map.put("rows", new ArrayList<AcWchatTvUserWeixinVo>());
        }
        return map;
	}

	public AcWchatTvUserWeixinVo selectAcMes(Map map){
	    Map<String,Object> listMap=new HashMap<String, Object>();
        AcWchatTvUserWeixinVo  newList=acDao.selectAcById(map);
	    return newList;
    }
    public Integer update(AcWchatTvUserWeixinVo vo){
	     Map<String,Object> map=new HashMap<String, Object>();
	     map.put("f_wtut_serverid",vo.getF_wtut_serverid());
         map.put("f_wtut_phone",vo.getF_wtut_phone());
         map.put("f_wtut_nickname",vo.getF_wtut_nickname());
         map.put("f_wtut_status",vo.getF_wtut_status());
         map.put("f_wtut_memo",vo.getF_wtut_memo());
         map.put("f_wtut_cdate",vo.getF_wtut_cdate());
         map.put("f_wtut_udate",vo.getF_wtut_udate());
         SysAreaStreetVo street=new SysAreaStreetVo();
         street.setF_sas_name(vo.getEndDate());
         street.setF_sas_id(Integer.parseInt(vo.getF_wtut_memo()));
        AcWchatTvGameVo game=new AcWchatTvGameVo();
        game.setF_wtgo_integral(vo.getBeginDate());
        game.setF_wtgo_weixinid(String.valueOf(vo.getF_wtut_id()));//微信号id
         try {
             acDao.wchatTvUpdate(vo);//更改itv账号
             acDao.wchatTvUp(game);//更改用户积分根据f_wtgo_weixinid
             acDao.streetUpdate(street);//更改社区街道名称
         }catch (Exception e){
             LOG.debug("异常信息"+e);
             return 0;
         }

        return 1;
    }
    public Integer bind(String f_wtut_serverid){
	    AcWchatTvUserWeixinVo map=new AcWchatTvUserWeixinVo();
	    map.setF_wtut_serverid(f_wtut_serverid);
       return acDao.wchatTvbind(map);
    }
    public Integer unbind(String f_wtut_serverid){
        AcWchatTvUserWeixinVo map=new AcWchatTvUserWeixinVo();
        map.setF_wtut_serverid(f_wtut_serverid);
       return acDao.wchatTvUnbind(map);
    }
    public Integer check(String f_wtut_serverid){
        AcWchatTvUserWeixinVo map=new AcWchatTvUserWeixinVo();
        map.setF_wtut_serverid(f_wtut_serverid);
       return acDao.check(map);
    }
    public Integer unCheck(String f_wtut_serverid){
        AcWchatTvUserWeixinVo map=new AcWchatTvUserWeixinVo();
        map.setF_wtut_serverid(f_wtut_serverid);
       return acDao.unCheck(map);
    }
    private static String Periods() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        int now = Integer.parseInt(sdf.format(new Date()));
        String type = "1";
        if(now>=20190328&&now<20190420) {
            type = "1";
        }else if(now>=20190420&&now<20190516) {
            type = "2";
        }else if(now>=20190516) {
            type = "3";
        }
        return type;
    }

}
